using BasicData.API.Application.Command;
using BasicData.API.Dtos;
using BasicData.ErrorCode;
using MediatR;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace BasicData.API.Application.Mediator
{
    /// <summary>
    /// 商品中介者实现
    /// </summary>
    public class GoodsMediator : IGoodsMediator
    {
        private readonly IMediator _mediator;
        private readonly ILogger<GoodsMediator> _logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">MediatR中介者</param>
        /// <param name="logger">日志</param>
        public GoodsMediator(IMediator mediator, ILogger<GoodsMediator> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }

        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="command">获取商品命令</param>
        /// <returns>商品列表</returns>
        public async Task<APIResult<List<GoodsDTO>>> GetGoodsAsync(GetGoodsCommand command)
        {
            _logger.LogInformation("通过中介者获取商品列表");
            return await _mediator.Send(command);
        }
    }
} 